package 正则匹配;

/**
 * @author wtcode
 * @date 2021/3/24 - 7:09
 */
public class Main {

    public boolean isMatch(String A,String B){
        int Alen = A.length();
        int Blen = B.length();
        boolean[][] res = new boolean[Alen+1][Blen+1];

        for(int i = 0 ; i < Alen ; i++){
            for(int j = 0 ; j < Blen ;j++){
                if(j==0){
                    res[i][j] = i==0;
                }else{
                    if(B.charAt(j - 1)!='*'){
                        if(i > 0 && A.charAt(i-1) == B.charAt(j-1) || B.charAt(j-1) == '.'){
                            res[i][j] = res[i-1][j-1];
                        }
                    }else{
                        // 不看
                        if(j >= 2){
                            res[i][j] = res[i][j-2];
                        }
                        // 看
                        if(i>=1 && j>=2 && A.charAt(i-1) == B.charAt(j-2) || B.charAt(j-2) == '.' ){
                            res[i][j] = res[i-1][j];
                        }
                    }
                }
            }
        }
        return res[Alen][Blen];
    }

}
